﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cloud.BLL;
using Cloud.Model;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class Three_Managerment_Problem_three_List_Zsk : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (IsPostBack)
            {

            }
            else
            {
                IList<ZS_TYPEINFO> suu = new List<ZS_TYPEINFO>();
                suu.Add(ZS_TYPEINFOManager.FindById(((USER_INFO)Session["users"]).DEPARTMENT));
                this.repeater1.DataSource = suu;
                this.repeater1.DataBind();
                bind();
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }

    protected void repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        try
        {
            if (e.CommandName.Equals("linkname"))
            {
                string id = Convert.ToString(e.CommandArgument);
                band(id);
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }

    protected void repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rep = e.Item.FindControl("rep1") as Repeater;//找到里层的repeater对象
                DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项 
                //ZS_INFO rowv = (ZS_INFO)e.Item.DataItem;
                string typeid = Convert.ToString(rowv["UNITID"]); //获取填充子类的id 
                IList<DW> sou = new List<DW>();
                sou.Add(DWManager.FindById(typeid));
                rep.DataSource = sou;
                rep.DataBind();
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }
    protected void AspNetPager_PageChanged(object sender, EventArgs e)
    {
        try
        {
            if (Session["users"] == null)
            {
                Response.Write("<script>alert('登录超时'); window.parent.location.href='/index.html'</script>");
            }
            bind();
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }

    public void bind()
    {
        try
        {
            string strbid = "select * from ZS_INFO where 1=1 and UNITID='" + ((USER_INFO)Session["users"]).DEPARTMENT + "' ";

            string strend = "  order by ID desc ";

            String sqls = strbid + strend;
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);
            SqlCommand cmd = new SqlCommand(sqls, connection);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            AspNetPager1.PageSize = 15;//设置分页大小 
            AspNetPager1.RecordCount = ZS_INFOManager.FindAll().Count;//设置总数据条数 
            sda.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "ZS_INFO");//固定不变的 
            repeater2.DataSource = ds.Tables["ZS_INFO"];
            repeater2.DataBind();
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }

    public void band(string id)
    {
        try
        {
            string strbid = "select * from ZS_INFO where 1=1 ";
            String strid = " and UNITID='" + id + "' ";
            string strend = "  order by ID desc ";



            String sqls = strbid + strid + strend;
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);
            SqlCommand cmd = new SqlCommand(sqls, connection);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            AspNetPager1.PageSize = 15;//设置分页大小 
            AspNetPager1.RecordCount = ZS_INFOManager.FindAll().Count;//设置总数据条数 
            sda.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "ZS_INFO");//固定不变的 
            repeater2.DataSource = ds.Tables["ZS_INFO"];
            repeater2.DataBind();
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }

    protected void repeater2_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        try
        {
            if (e.CommandName.Equals("delete"))
            {
                int id = Convert.ToInt32(e.CommandArgument);
                ZS_INFO z = ZS_INFOManager.FindById(id);
                if (ZS_INFOManager.Delete(z) > 0)
                {
                    Response.Write("<script>alert('删除成功')</script>");
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }
}